#!/bin/bash

if [[ $# -ne 2 ]]; then
    echo "The format is as follows:"
    echo "bash deeptools-2.0.0.sh buildpath installpath"
    echo ":param buildpath: 应用构建绝对路径"
    echo ":param installpath: 应用安装绝对路径"
    exit 1
fi

[[ ! "$1" =~ ^/.* || "$1" = "/" ]] &&  echo "请输入正确的构建路径" && exit 1
[[ ! "$2" =~ ^/.* || "$2" = "/" ]] &&  echo "请输入正确的安装路径" && exit 1

buildpath=$1
installpath=$2
[[ "$buildpath" =~ .*/$ ]] && buildpath=${buildpath%/*}
[[ "$installpath" =~ .*/$ ]] && installpath=${installpath%/*}
[[ "$buildpath" == "$installpath" ]] && echo "构建路径与安装路径需为不同路径" && exit 1
yum install -y  environment-modules csh time patch libatomic perl-Data-Dumper autoconf automake libtool numactl binutils systemd-devel valgrind flex wget

set -e
yum install numpy zlib-devel git -y

cd $buildpath
wget -t 10 -c https://github.com/deeptools/deepTools/archive/refs/tags/2.0.0.tar.gz 

tar -zxvf 2.0.0.tar.gz && rm -rf 2.0.0.tar.gz
cd $buildpath/deepTools-2.0.0

$installpath/python-2.7.18/bin/python setup.py install --prefix=$installpath/deeptools-2.0.0/

cat>"$installpath/deeptools-2.0.0/deeptools_modulefiles"<<EOF
#%Module1.0
conflict deeptools
variable modfile [file normalize [info script]]
proc getModulefileDir {} {
    variable modfile
    set modfile_path [file dirname \$modfile]
    return \$modfile_path
}
set pwd [getModulefileDir]
set DEEPTOOLS \$pwd
setenv DEEPTOOLS \$DEEPTOOLS
prepend-path PATH \$DEEPTOOLS/bin
prepend-path PYTHONPATH \$DEEPTOOLS/lib/python2.7/site-packages
EOF

rm -rf $buildpath/deepTools-2.0.0
